plugins: VOsc/VOsc3 - fix crash with negative buffer numbers
[supercollider.git] / examples / GUI examples / ScopeExample.scd
blobb22496d5815c321febcdff8d0c92730b424f8241
1 // thor magnusson (2007)
3 // Example showing how SCScope can be used in a UI
5 GUI.cocoa;      // use Mac OS X native GUI
6 GUI.swing;      // use Java GUI
9 s = Stethoscope.defaultServer;
10 s.waitForBoot({
11         var sc;
12         b = Buffer.alloc(s,2048,2);
13         a = SynthDef(\scopeExample, { arg freq=400, rate=2, amp=0.4, pan=0;
14                 var signal, scope;
15                 signal = [LFSaw.ar(freq, 0, amp/2)*SinOsc.ar(rate), 
16                                 Pulse.ar( freq, 0.51, amp)*SinOsc.ar(rate)];
17                 signal = Balance2.ar(signal[0], signal[1], pan);
18                 scope  = if( GUI.id === \cocoa, \ScopeOut, \JScopeOut ).asClass;
19                 scope.ar( signal, b );
20                 Out.ar(0, signal);
21         }).play(s);
22         
23         w = Window("scope in a gui", Rect(100, 400, 400, 300))
24                 .onClose_({a.free;}) // free synth on closing window
25                 .front;
27         MultiSliderView(w, Rect(10, 10, 90, 120))
28                 .value_([0.4, 0.5, 0.6, 0.5])
29                 .indexIsHorizontal_(false)
30                 .isFilled_(true)
31                 .strokeColor_(Color.new255(10, 55, 10))
32                 .fillColor_(Color.new255(110, 155, 110).alpha_(0.6))
33                 .indexThumbSize_(26)
34                 .gap_(4)
35                 .valueThumbSize_(1)
36                 .action_({|sl|
37                         sl.index.switch
38                                 {0} { a.set(\freq, 400+(sl.value[sl.index]*400)) }
39                                 {1} { a.set(\rate, (sl.value[sl.index]*10)) }
40                                 {2} { a.set(\amp, sl.value[sl.index]) }
41                                 {3} { a.set(\pan, (sl.value[sl.index]*2)-1) };
42                 });
43         
44         StaticText(w, Rect(14, 4, 90, 30))
45                 .string_("Freq");
46         StaticText(w, Rect(14, 34, 90, 30))
47                 .string_("Rate");
48         StaticText(w, Rect(14, 64, 90, 30))
49                 .string_("Amp");
50         StaticText(w, Rect(14, 94, 90, 30))
51                 .string_("Pan");
53         StaticText(w, Rect(10, 140, 90, 16))
54                 .string_("xZoom:");
56         Slider(w, Rect(10, 160, 90, 24))
57                 .action_({|sl| sc.xZoom_(sl.value*4)});
59         sc = ScopeView(w, Rect(120,10,260,260))
60                 .bufnum_(b.bufnum)
61                 .background_(Color.white)
62                 .resize_(5)
63                 .waveColors_([Color.black, Color.black]);
64 });